<?php
/**
* Class Contact into Home Controller
* @author SillySmart
* @copyright SillySmart
* @package Mvc.Controllers.Home
* @see Mvc.Controllers.Home.ControllerProtected
* @see Mvc.Controllers.SiteProtected
* @see Sls.Controllers.Core.SLS_GenericController
* @since 1.0
*
*/
class HomeContact extends HomeControllerProtected
{
	public function init()
	{
		parent::init();
	}

	public function action()
	{
		$qbd = new SLS_QueryBuilder();
		$xml = $this->getXml();
		$lang = $this->_lang->getLang();

		# Contact slider
		$xml->startTag('contact_slider');
		$contactSliderItems = $qbd->select('*')
			->from('contact_slider')
			->orderRand()
			->execute();

		foreach($contactSliderItems as $contactSliderItem)
		{
			$xml->startTag('contact_slider_item');
			foreach($contactSliderItem as $key => $value)
			{
				if(in_array($key, array('contact_slider_desktop_img', 'contact_slider_tablet_img')))
					$value = SLS_String::getUrlFile($value);
				$xml->addFullTag($key, $value, true);
			}
			$xml->endTag('contact_slider_item');
		}
		$xml->endTag('contact_slider');
		# /Contact slider

		# Contact feed
		$xml->startTag('contact_feed');
		$contactFeedItems = $qbd->select('*')
			->from('contact_feed')
			->where($qbd->expr()->eq('pk_lang', $lang))
			->order('contact_feed_id', 'desc')
			->execute();

		foreach($contactFeedItems as $contactFeedItem)
		{
			$xml->startTag('contact_feed_item');
			foreach($contactFeedItem as $key => $value)
			{
				if(in_array($key, array('contact_feed_ico', 'contact_feed_img')) && !empty($value))
					$value = SLS_String::getUrlFile($value);
				$xml->addFullTag($key, $value, true);
			}
			$xml->endTag('contact_feed_item');
		}
		$xml->endTag('contact_feed');
		# /Contact feed

		# Nav Projects
		$xml->startTag('nav_projects');
		$projects = $qbd->select('*')
			->from('project')
			->where($qbd->expr()->eq('pk_lang', $lang))
			->order('project_id', 'desc')
			->execute();

		foreach($projects as $project)
		{
			$xml->startTag('project');
			$xml->addFullTag('project_id', $project->project_id, true);
			$xml->endTag('project');
		}
		$xml->endTag('nav_projects');
		# /Nav Projects

		$this->saveXml($xml);
	}
}
?>